﻿using Sustainalytics.BusinessResearchProductStates.Entities.ResearchState;
using Sustainalytics.ScreeningTool.Synchronization.Caches;
using System.Threading.Tasks;

namespace Sustainalytics.ScreeningTool.Synchronization.Logging
{
    public class CacheLoaderDecorator<T> : ICacheLoader<T>
    {
        private readonly ICacheLoader _cacheLoader;

        public CacheLoaderDecorator(ICacheLoader<T> cacheLoader)
        {
            _cacheLoader = cacheLoader;
        }

        public async Task LoadAsync(ClientFacingProduct clientFacingProduct)
        {
            var cacheName = _cacheLoader.GetType().Name.Replace("Loader", "");
            var message = $"loading cache {cacheName}";

            await Log.Execution(message, () => _cacheLoader.LoadAsync(clientFacingProduct));
        }
    }
}
